package com.bootdo.market.dao;

import com.bootdo.market.domain.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface CommonDao {
    @Select("select `id`,`channelId`,`channelName`,`channelType`,`channelDes`,`createTime` from channel  where channelType=1")
    List<Map<String, Object>> list();

    @Select("select `id`,`channelId`,`channelName`,`channelType`,`channelDes`,`createTime` from channel where channelId = #{channelId} limit 1")
    ChannelDO getChannelNameByChannelid(@Param("channelId") String channelId);

    @Select("select `id`,`channelId`,`sdkId`,`sdkName`,`sdkVer`,`sdkDes`,`sdkType`,`createTime` from channel_sdk where channelId = #{channelId}")
    List<Map<String, Object>> SdkListByChannelid(@Param("channelId") String channelId);

    @Select("<script>" + " select `id`, (\n" +
            "        SELECT\n" +
            "        cha.channelName\n" +
            "        FROM\n" +
            "        channel cha\n" +
            "        WHERE\n" +
            "        cha.channelId = t.channelId\n" +
            "        ) channelName,\n" +
            "        (\n" +
            "        SELECT\n" +
            "        sd.sdkName\n" +
            "        FROM\n" +
            "        channel_sdk sd\n" +
            "        WHERE\n" +
            "        sd.sdkId = t.sdkId\n" +
            "        ) sdkName,`channelId`,`sdkId`,`channelDau`,`channelProfit`,`channelArpu`,\n" +
            "        `publishState`,DATE_FORMAT(createTime, '%Y-%m-%d' ) `createTime` from\n" +
            "        channel_profit t " +
            "where 1=1 "
            + "<if test=\"publishstate != null and publishstate != ''\">" +
            " and t.publishState = #{publishstate} </if>" +
            "            <if test=\"beginTime != null and beginTime != ''\">" +
            "                AND DATE_FORMAT(t.createTime, '%Y-%m-%d' ) &gt;= #{beginTime}" +
            "            </if>" +
            "            <if test=\"endTime != null and endTime != ''\">" +
            "                AND DATE_FORMAT(t.createTime, '%Y-%m-%d' ) &lt;= #{endTime}" +
            "            </if></script>")
    List<ChannelProfitDO> exportChannelData(Map<String, Object> params);

    @Select("select " +
            "\t\t\t`thirdSdkId` tsd,  " +
            "\t\t\t`isControlQuantity` icn," +
            "\t\t\tIFNULL(ControlQuantity,'')cn" +
            " from third_sdk where channelId = #{channelid} and sdkId = #{sdkid} and sdkType = #{sdktype} and isOperate = #{isoperate} ")
    List<Map<String, Object>> findNeizhi(Map<String, Object> params);

    @Select("select `thirdSdkId` tsd, \n" +
            "\t\t\t`thirdSdkName` fn, \n" +
            "\t\t\t`sdkPackName` pn, \n" +
            "\t\t\t`sdkMethodName` mn, \n" +
            "\t\t\t`isControlQuantity` icn, \n" +
            "IFNULL(ControlQuantity,'')cn," +
            "\t\t\t`sdkUrl` fu" +
            " from third_sdk where channelId = #{channelid} and sdkId = #{sdkid} and sdkType = #{sdktype} and isOperate = #{isoperate} ")
    List<Map<String, Object>> findRegengNormal(Map<String, Object> params);

    @Select("select " +
            "\t\t\t`thirdSdkName` fn" +
            " from third_sdk where channelId = #{channelid} and sdkId = #{sdkid} and sdkType = #{sdktype} and isOperate = #{isoperate}")
    List<Map<String, Object>> findRegengDelete(Map<String, Object> params);

    @Select("select `id`,`productName`,`productDomain`,`productDes`,`createTime` from product ")
    List<Map<String, Object>> listAllProduct();

    @Select("select    t.`id`,\n" +
            "        t.`channelId`,\n" +
            "        t.state,\n" +
            "        t.`productId`,\n" +
            "        t.`isChannelTemplate` from product_channel_relationship t where t.channelId = #{channelId} ")
    List<Map<String, Object>> findProductByChannelid(@Param("channelId") String channelId);

    @Select("select `id`,`productId`,`tagName`,`tagState`,`tagOnlineState`,`tagSort`,`createTime` from product_tags where productId = #{productid} and tagState=1  and tagOnlineState=1 ")
    List<Map<String, Object>> tagListByProductid(@Param("productid") Integer productid);

    @Select("select `id`,`advPositionTypeName`,`advPositionType`,`isDelete`,createTime from product_advposition_type ")
    List<Map<String, Object>> listProductAdvpositionType();

    @Select("SELECT\n" +
            "\tt.channelId,t.productId,pa.advPositionId,\n" +
            "(select prt.productName from product prt where prt.id=t.productId)productName,\n" +
            "(select pc.channelName from product_channel pc where pc.channelId=t.channelId)channelName,\n" +
            "pa.advPositionName,\n" +
            "pa.`advPositionWide`,\n" +
            "pa.`advPositionType`,\n" +
            "pa.`advPositionHeight`\n" +
            "FROM\n" +
            "\tproduct_channel_relationship t\n" +
            "LEFT JOIN product_advposition pa ON pa.productId = t.productId\n" +
            "WHERE\n" +
            "\tt.channelId = #{channelid}\n" +
            "AND t.productId = #{productid}\n" +
            "AND pa.advPositionId = #{advpositionid} limit 1")
    ProductAdvertisementDO getDataShow(ProductAdvertisementDO productAdvertisement);

    @Select("     SELECT\n" +
            "        t.channelId,\n" +
            "        pc.channelName\n" +
            "        FROM\n" +
            "        product_channel_relationship t\n" +
            "        LEFT JOIN product p ON t.productId = p.id\n" +
            "        LEFT JOIN product_channel pc ON t.channelId = pc.channelId\n" +
            "where  pc.channelState='1' and t.state=1 GROUP BY  pc.channelName,t.channelId ")
    List<Map<String, Object>> getVaildChannel();

    @Select(" SELECT\n" +
            "        t.productId,\n" +
            "        p.productName\n" +
            "        FROM\n" +
            "        product_channel_relationship t\n" +
            "        LEFT JOIN product p ON t.productId = p.id\n" +
            "        LEFT JOIN product_channel pc ON t.channelId = pc.channelId\n" +
            "where pc.channelState='1' and t.state=1 and t.channelId=#{channelid}  GROUP BY p.productName,t.productId")
    List<Map<String, Object>> getVaildProduct(@Param("channelid") Integer channelid);

    @Select("SELECT\n" +
            "\tgroup_concat((\n" +
            "\t\tCASE\n" +
            "\t\tWHEN area = ''\n" +
            "\t\tOR area IS NULL THEN\n" +
            "\t\t\tpareArea\n" +
            "\t\tELSE\n" +
            "\t\t\tarea\n" +
            "\t\tEND\n" +
            "\t)) area\n" +
            "FROM\n" +
            "\t product_adver_directional " +
            "WHERE\n " +
            "\tadvId=#{id}")
    List<String> findAreaIntoRedisOfferId(@Param("id") Integer id);

    @Select("select `id`,`advUnionName`,`advUnionType`,`advUnionUrl`,advUnionDes,`createTime` from platform_advunion ")
    List<Map<String, Object>> listAllAdvUnion();

    @Select("select `id`,`thirdSdkId`,`thirdName` from third_sdk t where t.isOperate='1' ")
    List<Map<String, Object>> listAllThirdSdk();

    @Select("SELECT\n" +
            "        t.`id`,\n" +
            "        t.`thirdSdkId`,\n" +
            "        ts.thirdName,\n" +
            "        pa.unionAccount,\n" +
            "        t.`advUnionId`,\n" +
            "        t.`unionAccountId`,\n" +
            "        t.`unionAppId`,\n" +
            "        t.`advShowRate`,\n" +
            "        t.`createTime`\n" +
            "        FROM\n" +
            "        third_sdk_advunion_relationship t\n" +
            "        LEFT JOIN platform_advunion_account pa ON t.unionAccountId = pa.id\n" +
            "        LEFT JOIN third_sdk ts ON ts.thirdSdkId=t.thirdSdkId where  t.unionAccountId = #{unionaccountid} ")
    List<Map<String, Object>> usedThirdSdkList(@Param("unionaccountid") Integer unionaccountid);

    @Select("SELECT\n" +
            "\tt.`id`,\n" +
            "\tt.`thirdSdkId`,\n" +
            "(select ts.thirdName FROM third_sdk ts where ts.thirdSdkId=t.thirdSdkId)thirdName,\n" +
            "\tt.`advUnionId`,\n" +
            "\tt.`unionAccountId`,\n" +
            "\tt.`unionAppId`,\n" +
            "\tt.`advShowRate`,\n" +
            "\tt.`createTime`\n" +
            "FROM\n" +
            "\tthird_sdk_advunion_relationship t where  t.unionAccountId = #{unionaccountid} ")
    List<Map<String, Object>> listRelaIdthirdSdk(@Param("unionaccountid") Integer unionaccountid);


    @Delete("delete from third_sdk_advunion_advposition_relationship where relaId = #{relaId}")
    void removerelationship(@Param("relaId") Integer relaId);

    @Select("select `id`,`thirdsdkId`,`advShowNum`,`advShowInterval`,`isShowBtn`,`createTime` from third_sdk_configure where thirdsdkId = #{thirdsdkid}")
    ThirdSdkConfigureDO JudgingUniqueConfig(@Param("thirdsdkid") String thirdsdkid);

    @Select("   SELECT\n" +
            "        t.`id`,\n" +
            "        t.`thirdSdkId`,\n" +
            "        ts.thirdName,\n" +
            "        pa.unionAccount,\n" +
            "        pfa.advUnionName,\n" +
            "        t.`advUnionId`,\n" +
            "        t.`unionAccountId`,\n" +
            "        t.`unionAppId`,\n" +
            "        t.`advShowRate`,\n" +
            "        t.`createTime`\n" +
            "        FROM\n" +
            "        third_sdk_advunion_relationship t\n" +
            "        LEFT JOIN platform_advunion_account pa ON t.unionAccountId = pa.id\n" +
            "        LEFT JOIN third_sdk ts ON ts.thirdSdkId=t.thirdSdkId LEFT JOIN platform_advunion pfa on pfa.id=t.advUnionId where  t.thirdSdkId = #{thirdsdkid}")
    List<ThirdSdkAdvunionRelationshipDO> saveAdconfigListAverage(Map<String, Object> params);

    @Select("    select `id`,`advUnionName`,`advUnionType`,`advUnionUrl`,`advUnionDes`,`createTime`\n" +
            " from platform_advunion")
    List<PlatformAdvunionDO> allAdvunionidList();

    @Select("select `id`,`advUnionId`,`unionAccount`,`unionPassWord`,`isLock`,`accountDes`,`createTime` from platform_advunion_account where advUnionId = #{advunionid}")
    List<PlatformAdvunionAccountDO> advunionidAccountList(Map<String, Object> params);

    @Select("SELECT\n" +
            "        t.`id`,\n" +
            "        t.`relaId`,\n" +
            "        t.`advPositionId`,\n" +
            "        ts.thirdName,\n" +
            "        t.`advPostitionName`,\n" +
            "        t.`advPositionType`,\n" +
            "        t.`advShowNum`,\n" +
            "        t.`isShowBtn`,\n" +
            "        t.`advPositionDes`,\n" +
            "        t.`createTime`\n" +
            "        FROM\n" +
            "        third_sdk_advunion_advposition_relationship t\n" +
            "        LEFT JOIN third_sdk_advunion_relationship tsa ON tsa.id = t.relaId\n" +
            "        LEFT JOIN third_sdk ts ON ts.thirdSdkId = tsa.thirdSdkId where tsa.thirdSdkId = #{thirdsdkid}")
    List<ThirdSdkAdvunionAdvpositionRelationshipDO> findAdvpositionconfigList(Map<String, Object> params);

    @Insert("insert into third_sdk_whitelist" +
            "(`thirdSdkId`, `whitelistId`) " +
            "values(#{thirdsdkid}, #{id})")
    void insertWhitelist(Map<String, Object> map);

    @Delete("delete from third_sdk_whitelist where id = #{thid}")
    void deleteWhitelist(@Param("thid") Integer thid);

    @Select("SELECT\n" +
            "\tcase when ts.isOperate='1' then 'true' else  'false' end as isOperate,\n" +
            "\tt.isShowBtn,\n" +
            "\tt.advShowInterval,\n" +
            "\tt.advShowNum\n" +
            "FROM\n" +
            "\tthird_sdk_configure t\n" +
            "LEFT JOIN third_sdk ts ON t.thirdsdkId = ts.thirdSdkId where  t.thirdsdkId = #{thirdsdkid}")
    Map<String, Object> findThirdConfig(Map<String, Object> params);

    @Select("SELECT\n" +
            "\tpw.packName\n" +
            "FROM\n" +
            "\tthird_sdk_whitelist t\n" +
            "LEFT JOIN platform_whitelist_dic pw ON pw.id = t.whitelistId\n" +
            "WHERE  t.thirdsdkId = #{thirdsdkid}")
    List<String> findpackNameConfig(Map<String, Object> params);

    @Select("SELECT\n  t.id," +
            "\tpa.advUnionType,\n" +
            "\tt.unionAppId,\n" +
            "\tt.unionAccountId,\n" +
            "\tt.advShowRate,\n" +
            "\tcase when paa.isLock='1' then 'true' else  'false' end as isLock\n" +
            "FROM\n" +
            "\tthird_sdk_advunion_relationship t\n" +
            "LEFT JOIN platform_advunion pa ON pa.id = t.advUnionId\n" +
            "LEFT JOIN platform_advunion_account paa ON paa.id = t.unionAccountId  " +
            "WHERE  t.thirdsdkId = #{thirdsdkid}")
    List<Map<String, Object>> findThirdadvunionRelationshipConfig(Map<String, Object> params);

    @Select("\t\tSELECT\n" +
            "\tt.`advPositionId` as advPositionId,\n" +
            "\tt.`advPositionType` as advPositionType,\n" +
            "\tt.`advShowNum` as showPrecent,\n" +
            "\tt.`isShowBtn` as isShowClose\n" +
            "FROM\n" +
            "\tthird_sdk_advunion_advposition_relationship t\n" +
            "LEFT JOIN third_sdk_advunion_relationship tsa ON tsa.id = t.relaId\n" +
            "WHERE  t.relaId = #{id}")
    List<Map<String, Object>> findThirdthirdAdvpositionRelationshipConfig(@Param("id") String id);

    @Select("\tSELECT\n" +
            "        t.`id`,\n" +
            "        t.`channelId`,\n" +
            "        t.state,\n" +
            "        p.productName,\n" +
            "        pc.channelName,\n" +
            "        t.`productId`,\n" +
            "        t.`isChannelTemplate`\n" +
            "        FROM\n" +
            "        product_channel_relationship t\n" +
            "        LEFT JOIN product p ON t.productId = p.id\n" +
            "        LEFT JOIN product_channel pc ON pc.channelId = t.channelId where t.channelId != #{channelid} and t.productId = #{productId} and t.state='1' and  t.`isChannelTemplate`='1'")
    List<Map<String, Object>> listChannelTemplate(ProductChannelDO productChannel);

    @Select(" SELECT\n" +
            "        t.`id`,\n" +
            "        t.`productId`,\n" +
            "        p.productName,\n" +
            "        t.`advPositionId`,\n" +
            "        pad.advPositionName,\n" +
            "        t.`channelId`,\n" +
            "        pc.channelName,\n" +
            "        t.`advName`,\n" +
            "        t.`advertiserName`,\n" +
            "        t.`advEvent`,\n" +
            "        t.`advDes`,\n" +
            "        t.`advDescription`,\n" +
            "        t.`advType`,\n" +
            "        t.`advPrice`,\n" +
            "        t.`advSort`,\n" +
            "        t.`advImgUrl`,\n" +
            "        t.`advUrl`,\n" +
            "        t.`advJs`,\n" +
            "        t.`advJsPathUrl`,\n" +
            "        t.`advNum`,\n" +
            "        t.`advSettlement`,\n" +
            "        t.`isDelete`,\n" +
            "        t.`publishState`,\n" +
            "        t.`isDirectional`,\n" +
            "        t.`createTime`\n" +
            "        FROM\n" +
            "        product_advertisement t LEFT JOIN product p ON p.id=t.productId LEFT JOIN product_advposition pad ON\n" +
            "        pad.advPositionId=t.advPositionId\n" +
            "        LEFT JOIN product_channel pc on t.channelId=pc.channelId where t.channelId = #{channelid} and t.productId = #{productid}")
    List<ProductAdvertisementDO> productAdvertisementDOList(ProductChannelRelationshipDO params);

    @Select("select area,pareArea as parent_area,advId as offer_id from product_adver_directional where advId=#{id}")
    List<Map<String, Object>> findAreaByOfferId(@Param("id") Integer id);

    @Select("select\n" +
            "        t.`id`,t.`articleSort`,t.`articleTitle`,t.`articleContent`,\n" +
            "        (select pt.tagName from product_tags pt where\n" +
            "        pt.id=t.tagId)tagname,\n" +
            "        (\n" +
            "        SELECT\n" +
            "        pro.productName\n" +
            "        FROM\n" +
            "        product pro\n" +
            "        WHERE\n" +
            "        pro.id = t.productId\n" +
            "        )\n" +
            "        productName,t.`articleCoverUrl`,t.`articleHistoryDate`,t.`articleHistoryMonthDay`,t.`publishState`,t.`deleteState`,t.`createTime`\n" +
            "        from product_article t")
    List<ProductArticleDO> batchRedisGetAllArticle();

    @Select(" select `id` as tagId,`productId`,`tagName`,`tagState`,`tagOnlineState`,`tagSort`,`createTime` from product_tags where tagState=1 and tagOnlineState=1  and productId=#{productId} ")
    List<Map<String, Object>> listAllTags(Map<String, Object> params);

    @Insert("insert into product_catalog_tags_relationship" +
            "(`catalogId`, `tagId`) " +
            "values(#{catalogId}, #{tagId})")
    void saveProductCatalogTags(Map<String, Object> params);

    @Select("select GROUP_CONCAT(tagId)tagId from product_catalog_tags_relationship t WHERE t.catalogId=#{id} GROUP BY t.catalogId ")
    String findProductCatalogTagsByCatalogId(@Param("id") Integer id);

    @Delete("delete from product_catalog_tags_relationship where catalogId = #{id}")
    void delProductCatalogTags(@Param("id") Integer id);

    @Select("<script>" + "select `id`,`productId`,`catalogName`,`catalogType`,`catalogUrl`,`catalogSort`,`catalogState`,`catalogOnlineState`,`catalogTemplate`,`catalogDes`,`createTime` from product_catalog " +
            "           where 1=1 "
            + "<if test=\"productid != null and productid != ''\">" +
            " and productId = #{productid} </if></script>"
    )
    List<Map<String, Object>> listAllCatalogs(Map<String, Object> params);

    @Select("select GROUP_CONCAT((select tagName from product_tags pt where pt.id= t.tagId))tagname from product_catalog_tags_relationship t WHERE t.catalogId=#{id} GROUP BY t.catalogId ")
    String findProductCatalogTagNamesByCatalogId(@Param("id") Integer id);

    @Select("select `channelId`,`channelName` from\n" +
            "        product_channel where channelState=1")
    List<Map<String, Object>> listAllChannel();

    @Select("select channelId from sys_user where channelStatus=2 and channelId!=null")
    List<Map<String, Object>> listUseProductChannel();

    @Select("select channelId from sys_user where channelStatus=1 and channelId!=null")
    List<Map<String, Object>> listUseChannel();

    @Select("select catalogId from product_catalog_tags_relationship where tagId=#{tagid} ")
    List<Integer> listCatalogByTagid(@Param("tagid") Integer tagid);

    @Select("select `id`,`catalogId`,`articleId`,`stickyPostsMonthDay`,`createTime` from product_stickyposts_calalog_article where catalogId = #{catalogId} and articleId = #{articleId} ")
    Map<String, Object> getStickypostsarticle(Map<String, Object> params);


    @Delete("delete from product_stickyposts_calalog_article where catalogId = #{catalogid} and stickyPostsMonthDay = #{stickypostsmonthday}")
    void deleteProductStickypostsCalalogArticle(StickypostsCalalogArticleDO stickypostsCalalogArticleDO);

    @Insert("insert into product_stickyposts_calalog_article" +
            "(`catalogId`, `articleId`,stickyPostsMonthDay) " +
            "values(#{catalogid}, #{articleid}, #{stickypostsmonthday})")
    void insertProductStickypostsCalalogArticle(StickypostsCalalogArticleDO stickypostsCalalogArticleDO);

    @Select(" SELECT\n" +
            "        t.`id`,\n" +
            "        t.`channelId`,\n" +
            "        t.state,\n" +
            "        t.linkName,\n" +
            "        t.settlementMethod,\n" +
            "        t.settlementPrice,\n" +
            "        t.channelSettlementRate,\n" +
            "        t.platformSettlementRate,\n" +
            "        t.description,\n" +
            "        p.productName,\n" +
            "        p.productDomain,\n" +
            "        pc.channelName,\n" +
            "        t.`productId`,\n" +
            "        t.`isChannelTemplate`\n" +
            "        FROM\n" +
            "        product_channel_relationship t\n" +
            "        LEFT JOIN product p ON t.productId = p.id\n" +
            "        LEFT JOIN product_channel pc ON pc.channelId = t.channelId" +
            " where    pc.channelState='1' and t.state=1 ")
    List<Map<String, Object>> getVaildChannelProduct();

    @Insert("insert into product_channel_profit" +
            "(`channelId`, \n" +
            "\t\t\t`productId`, \n" +
            "\t\t\t   linkName,\n" +
            "              settlementMethod,\n" +
            "                settlementPrice,\n" +
            "                channelSettlementRate,\n" +
            "                platformSettlementRate,\n" +
            "                `isChannelTemplate`,\n" +
            "\t\t\tstate,\n" +
            "\t\t\tdescription," +
            "historyDate) " +
            "values(#{channelId}, \n" +
            "\t\t\t#{productId},\n" +
            "\t\t\t#{linkName},\n" +
            "\t\t\t#{settlementMethod},\n" +
            "\t\t\t#{settlementPrice},\n" +
            "\t\t\t#{channelSettlementRate},\n" +
            "\t\t\t#{platformSettlementRate},\n" +
            "\t\t\t#{isChannelTemplate},\n" +
            "\t\t\t#{state},\n" +
            "\t\t\t#{description}," +
            "#{historyDate})")
    void insertVaildChannelProduct(Map<String, Object> params);

    @Select("<script>" + "select\n" +
            "        t.`id`,\n" +
            "        t.`channelId`,\n" +
            "        t.`productId`,\n" +
            "        t.`linkName`,\n" +
            "        t.`settlementMethod`,\n" +
            "        t.`settlementPrice`,\n" +
            "        t.`channelSettlementRate`,\n" +
            "        t.`platformSettlementRate`,\n" +
            "        t.`isChannelTemplate`,\n" +
            "        t.`state`,\n" +
            "        t.`description`,\n" +
            "        t.`historyDate`,\n" +
            "        t.`advertiserPV`,\n" +
            "        t.`advertiserUV`,\n" +
            "        t.`platformProfit`,\n" +
            "        t.`optparameters`,\n" +
            "        t.`channelSettlementAmount`,\n" +
            "        t.`publishState`,\n" +
            "        t.`platformeCPM`,\n" +
            "        t.`platformArup`,\n" +
            "        t.`showchannelPV`,\n" +
            "        t.`showchannelUV`,\n" +
            "        p.productName,\n" +
            "        p.productDomain,\n" +
            "        pc.channelName,\n" +
            "        t.`platformNetProfit`,\n" +
            "        t.`createTime`\n" +
            "        from product_channel_profit t\n" +
            "        LEFT JOIN product p ON t.productId = p.id\n" +
            "        LEFT JOIN product_channel pc ON pc.channelId = t.channelId " +
            " where 1=1 "
            + "<if test=\"channelid != null and channelid != ''\">and t.channelId = #{channelid}</if>\n" +
            "            <if test=\"productid != null and productid != ''\">and t.productId = #{productid}</if>\n" +
            "            <if test=\"publishstate != null and publishstate != ''\">and t.publishState = #{publishstate}</if>\n" +
            "            <if test=\"linkname != null and linkname != ''\">and t.linkName like CONCAT('%',#{linkname},'%')</if>" +
            " <if test=\"beginTime != null and beginTime != ''\">\n" +
            "                AND DATE_FORMAT(t.historyDate, '%Y-%m-%d' ) &gt;= #{beginTime}\n" +
            "            </if>\n" +
            "            <if test=\"endTime != null and endTime != ''\">\n" +
            "                AND DATE_FORMAT(t.historyDate, '%Y-%m-%d' ) &lt;= #{endTime}\n" +
            "            </if>" +
            "" +"     order by t.id desc"+
            "</script>")
    List<ProductChannelProfitDO> listProductChannelProfitDO(Map<String, Object> params);

    @Select(" SELECT\n" +
            "        t.`id`,\n" +
            "        t.`productId`,\n" +
            "        p.productName,\n" +
            "        t.`advPositionId`,\n" +
            "        t.advContent,\n" +
            "        t.settlementPosition,\n" +
            "        t.settlementW,\n" +
            "        t.settlementH,\n" +
            "        pad.advPositionName,\n" +
            "        t.`channelId`,\n" +
            "        pc.channelName,\n" +
            "        t.`advName`,\n" +
            "        t.`advertiserName`,\n" +
            "        t.`advEvent`,\n" +
            "        t.`advDes`,\n" +
            "        t.advDescription,\n" +
            "        t.`advType`,\n" +
            "        t.`advPrice`,\n" +
            "        t.`advSort`,\n" +
            "        t.`advImgUrl`,\n" +
            "        t.`advUrl`,\n" +
            "        t.`advJs`,\n" +
            "        t.advJsPathUrl,\n" +
            "        t.`advNum`,\n" +
            "        t.`advSettlement`,\n" +
            "        t.`isDelete`,\n" +
            "        t.`publishState`,\n" +
            "        t.`isDirectional`,\n" +
            "        t.`createTime`\n" +
            "        FROM\n" +
            "        product_advertisement t LEFT JOIN product p ON p.id=t.productId LEFT JOIN product_advposition pad ON\n" +
            "        pad.advPositionId=t.advPositionId\n" +
            "        LEFT JOIN product_channel pc on t.channelId=pc.channelId")
    List<ProductAdvertisementDO> batchRedisGetAllProductAdvertisement();

    @Select("SELECT\n" +
            "        t.`id`,\n" +
            "        t.`advPositionId`,\n" +
            "        t.`productId`,\n" +
            "        t.advInterval,\n" +
            "        t.catalogId,\n" +
            "        (select catalogName from product_catalog c where c.id = t.catalogId)catalogName,\n" +
            "        p.productName,\n" +
            "        pt.advPositionTypeName,\n" +
            "        pt.advPositionType,\n" +
            "        t.`advPositionName`,\n" +
            "        t.`advPositionWide`,\n" +
            "        t.`advPositionHeight`,\n" +
            "        t.`imgSizeDes`,\n" +
            "        t.`imgScaleDes`,\n" +
            "        t.`imgFormatDes`,\n" +
            "        t.`isSsp`,\n" +
            "        t.`isDelete`,\n" +
            "        t.`createTime`\n" +
            "        FROM\n" +
            "        product_advposition t LEFT JOIN product p on t.productId=p.id\n" +
            "        LEFT JOIN product_advposition_type pt ON pt.advPositionType=t.advPositionType")
    List<ProductAdvpositionDO> batchRedisGetAllProductAdvposition();

    @Select(" SELECT\n" +
            "        t.`id`,\n" +
            "        t.`productId`,\n" +
            "        p.productName,\n" +
            "        t.`advPositionId`,\n" +
            "        t.advContent,\n" +
            "        t.settlementPosition,\n" +
            "        t.settlementW,\n" +
            "        t.settlementH,\n" +
            "        pad.advPositionName,\n" +
            "        t.`channelId`,\n" +
            "        pc.channelName,\n" +
            "        t.`advName`,\n" +
            "        t.`advertiserName`,\n" +
            "        t.`advEvent`,\n" +
            "        t.`advDes`,\n" +
            "        t.advDescription,\n" +
            "        t.`advType`,\n" +
            "        t.`advPrice`,\n" +
            "        t.`advSort`,\n" +
            "        t.`advImgUrl`,\n" +
            "        t.`advUrl`,\n" +
            "        t.`advJs`,\n" +
            "        t.advJsPathUrl,\n" +
            "        t.`advNum`,\n" +
            "        t.`advSettlement`,\n" +
            "        t.`isDelete`,\n" +
            "        t.`publishState`,\n" +
            "        t.`isDirectional`,\n" +
            "        t.`createTime`\n" +
            "        FROM\n" +
            "        product_advertisement t LEFT JOIN product p ON p.id=t.productId LEFT JOIN product_advposition pad ON\n" +
            "        pad.advPositionId=t.advPositionId\n" +
            "        LEFT JOIN product_channel pc on t.channelId=pc.channelId where t.isDelete=1 and t.publishState=1 and t.productId=#{productid} and t.advPositionId=#{advpositionid} and t.channelId=#{channelid} order by t.advSort")
    List<ProductAdvertisementDO> listProductAdvertisement(ProductAdvertisementDO aaaa);

}
